<template>
    <div class="cmt-container">
        <h3>发表评论</h3>
        <hr>
        <textarea v-model="msg" placeholder="请输入评论的内容（最多吐槽120字）" maxlength="120"></textarea>  

        <mt-button type="primary" size="large" @click="postComment">发表评论</mt-button>  
         
         <div class="cmt-list">
            <div class="cmt-item" v-for="(item,index) in comments" :key="item.add_time">
                <div class="cmt-title">
                    第{{index+1}}楼&nbsp;&nbsp;用户：{{item.user_name}}&nbsp;&nbsp;发表时间:{{item.add_time}}
                </div>
                   <div class="cmt-body">
                       {{item.content}}
                </div>
            </div>
         </div>
        <mt-button type="danger" size="large" plain @click="getMore">加载更多</mt-button>
    </div>
</template>

<script>
export default {
  data() {
    return {
      comments: [],
      msg: ""
    };
  },
  created() {
    this.getCommentList();
  },
  methods: {
    getCommentList() {
      console.log(this.id);
      this.comments = [
        {
          username: "张三",
          add_time: "2012-12-12 12:13:12",
          content: "我来评论一下"
        },
        {
          username: "张三",
          add_time: "2012-12-12 12:14:12",
          content: "我来评论一下"
        },
        {
          username: "张三",
          add_time: "2012-12-12 12:15:12",
          content: "我来评论一下"
        },
        {
          username: "张三",
          add_time: "2012-12-16 12:12:12",
          content: "我来评论一下"
        }
      ];
      this.$http
        .get("https://www.baidu.com/?tn=62095104_7_oem_dg")
        .then(result => {
          console.log(result);
        });
    },
    getMore() {
      console.log("getMore is doing");
    },
    postComment() {
      console.log("评论内容" + this.msg);
      var cmt = {
        user_name: "匿名用户",
        add_time: "2012-12-12 12:16:15",
        content: this.msg
      };
      this.comments.unshift(cmt);
      this.msg=""
    }
  },
  props: ["id"]
};
</script>


<style lang="scss" scoped>
.cmt-container {
  background-color: #fff;
  h3 {
    font-size: 18px;
  }
  textarea {
    font-size: 14px;
    height: 85px;
    margin: 0;
  }
  .cmt-list {
    margin: 5px 0;
    .cmt-item {
      font-size: 13px;
      .cmt-title {
        line-height: 30px;
        background-color: #ccc;
      }
      .cmt-body {
        line-height: 35px;
        text-indent: 2em;
      }
    }
  }
}
</style>
